/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.brain.clima.view.util;

import java.lang.reflect.InvocationTargetException;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.beanutils.BeanUtils;



/**
 *
 * @author Cristian
 */
public class Comparador implements Comparator{
    
    private String nameField;   
    
    public Comparador(String nameField){
        this.nameField = nameField;
    }
/*
    @Override
    public int compare(PreguntaDto o1, PreguntaDto o2) {
        return o1.getOrden().compareTo(o2.getOrden());
    }    
    */

    @Override
    public int compare(Object object1, Object object2) {
        try {
            return BeanUtils.getProperty(object1, nameField).compareTo(BeanUtils.getProperty(object2, nameField));
        } catch (IllegalAccessException ex) {
            Logger.getLogger(Comparador.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvocationTargetException ex) {
            Logger.getLogger(Comparador.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchMethodException ex) {
            Logger.getLogger(Comparador.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
    }

    
}
